package com.common.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * 视图处理器
 * @author YYQ
 *
 */
@Configuration
public class WebMVCConfig implements WebMvcConfigurer {

    @Value("${file.upload.path}")
    private String uploadFolder;

    /**
     * 静态文件路径设置
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        // String path1 = ResourceUtils.getURL("classpath:").getPath();
        // String path2 = ClassUtils.getDefaultClassLoader().getResource("").getPath();

        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/static/", "file:" + uploadFolder);// 上传的图片代理文件夹路径
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
    }

    /**
     * 拦截器配置
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new InterceptorConfig())
                .addPathPatterns("/**");//所有请求都被拦截，包括静态资源
        /*registry.addInterceptor(new InterceptorConfig())
                .addPathPatterns("/**")//所有请求都被拦截，包括静态资源
                .excludePathPatterns("/","/login","/css/**","/fonts/**","/images/**","/js/**");//放行的请求*/
    }




}